﻿@model dsacbasic.Models.ListUsersInfo
@{
    ViewBag.Title = "用户管理";
}
<div style="height: 40px; line-height: 40px; padding: 0 10px;">
    <div class="pull-right" style="height: 40px; line-height: 40px;">
        <a href='@Url.Action("Excel", new { cate = Request.QueryString["cate"], keyword = Request.QueryString["keyword"] })' target="_blank" class="btn  btn-primary btn-large">
            <i class="icon-list icon-white"></i>导出Excel</a>
    </div>
    <div style="height: 40px; line-height: 40px;">
        <h2 id="bigTitle">
            @ViewBag.Title
        </h2>
    </div>
</div>
<hr />
<div class="row" style="margin-top: 20px;">
    <div class="searchBar">
        用户级别：<select id="searchCate">
            <option value="-1"></option>
            @{foreach (var cate in Model.Search.Cates)
              {
                  if (Model.Search.CurrentCate == cate.ID)
                  {
                <option selected="selected" value="@cate.ID">@cate.Name</option>
                  }
                  else
                  {
                <option value="@cate.ID">@cate.Name</option>
                  }
              }
            }
        </select>
        用户名：<input type="text" id="searchText" value="@Model.Search.Keyword" />
        <input type="button" id="searchBtn" value="搜索" />
    </div>
</div>
@Html.Partial("MessageTip")
<table class="table table-bordered">
    <thead>
        <tr>
            <th>
                用户名
            </th>
            <th>
                真实姓名
            </th>
            <th>
                EMail
            </th>
            <th>
                电话
            </th>
            <th>
                注册时间
            </th>
            <th>
                用户级别
            </th>
            <th>
                操作
            </th>
        </tr>
    </thead>
    <tbody>
        @foreach (GADC.Domain.Users obj in Model.List)
        {
            <tr>
                <td>
                    @obj.Name
                </td>
                <td>
                    @obj.Realname
                </td>
                <td>
                    @obj.Email
                </td>
                <td>
                    @obj.Telephone
                </td>
                <td>
                    @(obj.Registertime != null ? obj.Registertime.ToString("yyyy-MM-dd") : "")
                </td>
                <td>
                    @(obj.Level != null ? obj.Level.Name : "")
                </td>
                <td>
                    <a class="operate" href="javascript:EditLevel(@obj.ID,@obj.Level.ID)">修改级别</a>
                    <a class="operate" href="javascript:ResetPassword(@obj.ID)">密码重置</a>
                    <a class="operate" href="javascript:Operating(-1,@obj.ID)">删除</a>
                    <br />
                </td>
            </tr>
        }
    </tbody>
</table>
@Html.Partial("Pager", Model.Pager, new ViewDataDictionary() { { "Keyword", Model.Search.Keyword }, { "CurrentCate", Model.Search.CurrentCate } })
<form id="hideForm" action='@Url.Action("Operate")' method="post">
<input type="hidden" id="Operate" name="Operate" />
<input type="hidden" id="ID" name="ID" />
</form>

<form id="hideForm2" action='@Url.Action("ResetPassword")' method="post">
<input type="hidden" id="UserID2" name="UserID2" />
</form>
<div class="modal hide fade" id="addOne-modal" data-backdrop="static" data-keyboard="false">
    <form id="cateForm" action='@Url.Action("EditLevel")' method="post">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
            ×</button>
        <h3 id="myModalLabel">
            修改级别</h3>
    </div>
    <br />
    <fieldset>
        <div class="span5">
            <input type="hidden" name="UserID" id="UserID" />
            <select name="LevelID" id="LevelID" style=" width:400px;">
                @{foreach (var cate in Model.Search.Cates)
                  {
                    <option value="@cate.ID">@cate.Name</option>
                  }
                }
            </select>
        </div>
        <div class="span1 offset2">
            <input type="submit" id="recipe-btn" value="保 存" class="btn btn-blue span1" />
        </div>
    </fieldset>
    </form>
</div>

@section scripts{
    @Html.Partial("SearchScript", Model.Search)
    <script type="text/javascript">
        function Operating(operateType, id) {
            if (operateType == -1) {
                if (!window.confirm("确定删除该记录?")) {
                    return false;
                }
            }

            $("#Operate").val(operateType);
            $("#ID").val(id);
            $("#hideForm").submit();
        }

        function EditLevel(uid,lid) {
            $("#UserID").val(uid);
            $("#LevelID").val(lid);
            $('#addOne-modal').modal('show');
        }


        function ResetPassword(uid) {
            if (window.confirm("确定重置密码?")) {
                $("#UserID2").val(uid);
                $("#hideForm2").submit();
            }
        }
    </script>
}
